const fs = require("fs");

function delDir(dirPath) {
    let fileArr = fs.readdirSync(dirPath);
    for (let i in fileArr) {
        let filePath = delDir + '/' + fileArr[i];
        //读取文件信息
        let stat = fs.statSync(filePath);
        //判断是否是文件
        if (stat.isFile()) {
            fs.unlinkSync(filePath);
        } else if (stat.isDirectory()) {
            delDir(filePath);
        }
    }
    fs.rmdirSync(dirPath)
}


delDir('./file')